package com.dream.service.recommender.toolkits.utils;


/**
 * Created by zhiji on 2016/3/24.
 */
public class CheckUtil {

	private static String uuid_pattern = "[a-zA-Z0-9-]{5,128}";
	private static String pin_pattern = "[a-zA-Z0-9-]{5,128}";

	public static boolean isvalidUUid(String uuid) {
		return isvalidUUid(uuid, true);
	}

	/**
	 * uuid是否合法
	 * 
	 * @param uuid
	 * @param canempty 是否可以为空
	 * @return
	 */
	public static boolean isvalidUUid(String uuid, boolean canempty) {
		if (canempty) {
			return StringUtils.isEmpty(uuid) || StringUtils.ismatch(uuid, uuid_pattern);
		}
		return !StringUtils.isEmpty(uuid) && StringUtils.ismatch(uuid, uuid_pattern);
	}

	public static boolean isvalidPin(String pin) {
		return isvalidPin(pin, true);
	}

	/**
	 * pin 是否合法
	 * @param pin
	 * @param canEmpty 是否可以为空
	 * @return
	 */
	public static boolean isvalidPin(String pin, boolean canEmpty) {
		if (canEmpty) {
			return StringUtils.isEmpty(pin) || StringUtils.ismatch(pin, pin_pattern);
		}
		return !StringUtils.isEmpty(pin) && StringUtils.ismatch(pin, pin_pattern);
	}
}
